﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DoodJetView.Core.Reservation;
using DoodJetView.Core;
using System.Timers;
using Doo_JetDAL;

namespace DoodJetView.VuesPartielles
{
    /// <summary>
    /// Logique d'interaction pour DashBoard.xaml
    /// </summary>
    public partial class DashBoard : UserControl
    {
        public DashBoard()
        {
            InitializeComponent();
            this.DataReservations.ItemsSource = this.PreparerLesDonnées(GestionReservation.whatHaveInDay());

            //DataReservations.Columns.Clear();
        }

        private System.Collections.IEnumerable PreparerLesDonnées(List<Reservation.EquipementResult> list)
        {
            equipements eq = null;
            List<AffichageReservation> ret = new List<AffichageReservation>();
            using (DataEntities db = new DataEntities())
            { 
            
                foreach (Reservation.EquipementResult r in list)
                {
                    eq = db.equipements.SingleOrDefault(o => o.id_equipement == r.id_equipement);
                    ret.Add(new AffichageReservation { 
                        Date = DateTimeUnixTools.ConvertFromUnixTimestamp(r.dateDebut).ToString("dd/MM/yyyy"),
                        Heure = DateTimeUnixTools.ConvertFromUnixTimestamp(r.dateDebut).ToString("hh:mm"),
                        Duree = r.dateFin - r.dateDebut,
                        TypeActivite = eq.TypeEquipement.libelle,
                        Machine = eq.nomEquipement,
                        NomClient = r.nomClient,
                        PrenomCLient = r.prenomClient
                    });
                }
            }
            return ret;
        }

        


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.DataReservations.ItemsSource = this.PreparerLesDonnées(GestionReservation.whatHaveInDay());

        }

        
    }
}
